<?php
/* non ancora utilizzata */
class Redirect {
    
    /**
    * Redirect , funziona con url assoluti e non sempre , dipende dal conf server
    *
    * @param string $url URL.
    * @param array $post_data
    * @param array $headers  opzionale
    * 
    */
    public function redirect_post($url, array $data, array $headers = null) {
        $params = array('http' => array('method' => 'POST', 'content' => http_build_query($data)));
        if (!is_null($headers)) {
            $params['http']['header'] = '';
            foreach ($headers as $k => $v) {
                $params['http']['header'] .= "$k: $v\n";
            }
        }
        $ctx = stream_context_create($params);
        $fp = @fopen($url, 'rb', false, $ctx);
        if ($fp) {
            echo @stream_get_contents($fp);
            die();
        } else {
            // Error
            throw new Exception("Error loading '$url', $php_errormsg");
        }
    }
    
    public function redirect_post_curl($url, array $data) {
    	$ch = curl_init();
		curl_setopt($ch,CURLOPT_URL,$url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch,CURLOPT_POST,count($data));
		curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query($data));		
		$result = curl_exec($ch);
        curl_close ($ch);
        unset($ch);
        echo $result;
    }
}

?>